import base64
import numpy as np
import cv2


# 输入包含单个人脸的图片，提取该人脸特征和位置框(left,top,right,bottom)
def get_feature_face_from_file(model,img_file):
    img = cv2.imread(img_file)
    box,img = model.get_input(img)
    fea = model.get_feature(img)
    return box,fea


def get_feature_faces_from_file(model,img_file):
    img=cv2.imread(img_file)
    boxes,imgs = model.get_inputs(img)
    features=[]
    for i in range(boxes.shape[0]):
        fea = model.get_feature(imgs[i])
        features.append(fea)
    return boxes,features


# 输入包含单个人脸的cv2图片矩阵BGR，提取该人脸特征和位置框(left,top,right,bottom)
def get_feature_face_from_bgrarray(model,img_array):
    box,img = model.get_input(img_array)
    fea = model.get_feature(img)
    return box,fea


def get_feature_faces_from_bgrarray(model,img_array):
    boxes,imgs = model.get_inputs(img_array)
    features=[]
    for i in range(boxes.shape[0]):
        fea = model.get_feature(imgs[i])
        features.append(fea)
    return boxes,features



if __name__=='__main__':
    for i in range(1,5):
        boxes,features=get_feature_faces_from_file('test'+str(i)+'.png')
        print()


